#ifndef __PART_H__
#define __PART_H__

#include <time.h>
#include "upper.h"

#define PART_ERROR_BASE 800

#define SAMPLE_TIME    (get_sample_time()*20)

enum part_error{
    DEVICE_BUSY = PART_ERROR_BASE + 1,
    COMM_TIMEOUT,
    MISSING_PARAM,
    OXC_ATTN_NOT_ABS
};

typedef struct _device{
    char busy;
    int exit;
    int uart_fd;
    int sample_flag;
    int print_flag;
    char* device_name;
    timer* timer;
}device;

int open_uart(char* uart_no,int speed,int bits,char event,int stop);
void close_uart(int fd);
int set_speed_uart(int fd,int speed);
int write_tty(device* p_device,char *send_buf,int len);
int read_tty(device* p_device,char *recv_buf,int len,int sec,int usec);
int query_tty(device* p_device,char* send_buf,int slen,char* recv_buf,int rlen,int sec,int usec);
int query_tty_time(device* p_device,char* send_buf,int slen,char* recv_buf,int rlen,int sec,int usec,clock_t* usage_time);
void part_alarm_register(device_alarm_list* p_list);

cJSON* part_default(int cmd_id);
#endif // !__PART_H__
